package com.yuan.admin.controller;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Controller

public class UploadController {
    /***
     *
     *
     * 传文件，返回文件名称
     * @return
     */
    @GetMapping("/uploads")
    public String upload(){
        return "upload";
    }

    /***
     *
     * @return
     */
    @PostMapping("upload")
    public String upfile(@RequestParam("file") MultipartFile file){
        String contentType = file.getContentType();   //图片文件类型
        String fileName = file.getOriginalFilename(); //图片名字
        System.out.println(file.getContentType());
        File dest = new File( fileName);
        try {
            file.transferTo(dest);
            return "上传成功";
        } catch (IOException e) {

        }
        return "upload";
    }
}
